Skip to content

fix: request analyzer stats fields#718

Merged
valscion merged 2 commits into
webpack:mainfrom
SyMind:codex/pass-stats-options-to-analyzer
Jun 15, 2026
Merged

fix: request analyzer stats fields#718
valscion merged 2 commits into
webpack:mainfrom
SyMind:codex/pass-stats-options-to-analyzer

Conversation

@SyMind

@SyMind SyMind commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Rspack 2.0 changed the default stats.toJson() output so fields like modules, assets, chunks, chunkGroups, and entryPoints are no longer included unless requested explicitly. See the Rspack v2 migration guide.

That can leave webpack-bundle-analyzer with incomplete stats when it runs against Rspack 2.0. This PR makes analyzer modes request the stats fields they need directly instead of relying on compiler defaults.

Changes

  • Add internal stats options for bundle analysis.
  • Use them in server, static, and json analyzer modes.
  • Keep user-provided statsOptions scoped to generated stats files.
  • Add regression tests and a patch changeset.

Notes

statsOptions remains user-controlled because users may intentionally filter fields such as assets or modules. Analyzer report generation needs a stable minimum stats shape, so it uses dedicated internal options.

Validation

  • npm test
  • npm run lint
  • npm run build:analyzer
  • npm run lint:types
  • Targeted Jest, ESLint, and Prettier checks for the touched files.

@changeset-bot

changeset-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11af922

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-bundle-analyzer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@SyMind SyMind marked this pull request as ready for review June 12, 2026 07:25
Copilot AI review requested due to automatic review settings June 12, 2026 07:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for forwarding statsOptions from BundleAnalyzerPlugin options into stats.toJson(...), ensuring analyzer/report generation uses the intended webpack stats shape.

Changes:

  • Pass this.opts.statsOptions into stats.toJson(...) for server, static, and json analyzer modes.
  • Add Jest coverage to verify statsOptions is forwarded and the chosen analyzer method receives the resulting stats JSON.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/plugin.js Adds parameterized tests validating statsOptions propagation across analyzer modes.
src/BundleAnalyzerPlugin.js Updates plugin to call stats.toJson(this.opts.statsOptions) when generating analyzer outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SyMind SyMind force-pushed the codex/pass-stats-options-to-analyzer branch from 36d30b5 to bdb4e2f Compare June 12, 2026 08:05
@SyMind SyMind changed the title fix: pass statsOptions to analyzer modes fix: request analyzer stats fields Jun 12, 2026
@SyMind SyMind force-pushed the codex/pass-stats-options-to-analyzer branch from bdb4e2f to 8049c31 Compare June 12, 2026 08:12
Copilot AI review requested due to automatic review settings June 12, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread src/BundleAnalyzerPlugin.js
Comment thread src/BundleAnalyzerPlugin.js
Comment thread src/BundleAnalyzerPlugin.js
Comment thread src/BundleAnalyzerPlugin.js

@valscion valscion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What use case needs this? Never heard of this kind of need in the past

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.29%. Comparing base (a2ae1ef) to head (11af922).

Files with missing lines Patch % Lines
src/BundleAnalyzerPlugin.js 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #718      +/-   ##
==========================================
- Coverage   76.30%   76.29%   -0.01%     
==========================================
  Files          17       17              
  Lines         979      983       +4     
  Branches      357      357              
==========================================
+ Hits          747      750       +3     
- Misses        205      206       +1     
  Partials       27       27              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SyMind

SyMind commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@valscion This is mainly for Rspack 2.0 compatibility.

Rspack 2.0 changed the default output of stats.toJson(): fields such as modules, assets, chunks, chunkGroups, and entryPoints are no longer included by default unless requested explicitly:
https://rspack.rs/guide/migration/rspack_1.x#changed-default-parameters-of-statstojson

webpack-bundle-analyzer currently calls stats.toJson() without options in analyzer modes, so with Rspack 2.0 it can receive incomplete stats and fail to build the expected bundle analysis data.

The goal of this PR is to make the analyzer request the minimum stats shape it depends on, instead of relying on compiler-specific defaults.

@valscion valscion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm OK, thanks for explaining! I do understand this better now.

Now I wonder if there's any way to add reasonable test coverage for this... we don't really support Rspack in the sense of having any guarantees of it working here nor do we want to have CI test against it as it brings additional maintenance burden to verify it doesn't break here.

But this is such a small change and doesn't seem brittle so might as well have it. I'll modify the changeset a bit to describe this stance on Rspack.

Explicitly define `stats.toJson()` options for bundle analysis to support Rspack 2.0 with minimal code changes needed.
@valscion valscion merged commit 5ec0e7c into webpack:main Jun 15, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants